package ch.ethz.fcl.metrobuzz.render.accessbility.interaction;

import java.awt.Color;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import ch.ethz.fcl.metrobuzz.render.accessbility.AccessibilityRender;

public class AcceLocalPanel extends JPanel {
	private static final long serialVersionUID = -7121811087445725047L;

	private JCheckBox flowMapCB;
	private JCheckBox isochroneCB;

	public AcceLocalPanel() {
		setBackground(Color.lightGray);
		setBorder(BorderFactory.createTitledBorder("Accessibility Control"));
		setLayout(new MigLayout());

		flowMapCB = new JCheckBox("        Flow Map View",
				AccessibilityRender.FLOW_MAP_VIEW);
		flowMapCB.setBackground(Color.LIGHT_GRAY);
		flowMapCB.addItemListener(new CheckBoxChangeListener());

		isochroneCB = new JCheckBox("        Isochrones View",
				AccessibilityRender.ISOCHRONE_VIEW);
		isochroneCB.setBackground(Color.LIGHT_GRAY);
		isochroneCB.addItemListener(new CheckBoxChangeListener());

		this.add(flowMapCB, "wrap");
		this.add(isochroneCB, "wrap");
	}
	
	public JCheckBox getFlowMapCB(){
		return flowMapCB;
	}
	
	public JCheckBox getIsochroneCB(){
		return isochroneCB;
	}

	class CheckBoxChangeListener implements ItemListener {
		@Override
		public void itemStateChanged(ItemEvent event) {
			Object source = event.getSource();
			if (source instanceof JCheckBox) {
				JCheckBox cb = (JCheckBox) source;
				if (cb.isSelected()) {
					if (cb.getText().contains("Flow Map View")) {
						AccessibilityRender.FLOW_MAP_VIEW = true;
					} else if (cb.getText().contains("Isochrones View")) {
						AccessibilityRender.ISOCHRONE_VIEW = true;
					}

				} else {
					if (cb.getText().contains("Flow Map View"))
						AccessibilityRender.FLOW_MAP_VIEW = false;
					else if (cb.getText().contains("Isochrones View"))
						AccessibilityRender.ISOCHRONE_VIEW = false;
				}
			}
		}
	}
}
